import sys
from PySide6.QtWidgets import QApplication, QMainWindow, QToolBar, QStyle, QSizePolicy,QWidget,QVBoxLayout
from PySide6.QtGui import QAction
from PySide6.QtCore import Qt

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("三行工具栏")
        self.resize(800, 200)

        # 1. 建一个中心控件，用来竖排工具栏
        central = QWidget()
        self.setCentralWidget(central)
        lay = QVBoxLayout(central)
        lay.setContentsMargins(0, 0, 0, 0)
        lay.setSpacing(0)

        # 2. 三条工具栏
        for row in range(3):
            bar = QToolBar(f"Row{row+1}")
            self.populate(bar)
            # 允许横向拉伸，纵向固定
            bar.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
            lay.addWidget(bar)

        # 3. 把剩余空间挤到下面，防止工具栏被拉伸
        lay.addStretch()

    def populate(self, bar):
        names = ["SP_FileIcon", "SP_DirIcon", "SP_DialogSaveButton"]
        for n in names:
            ico = self.style().standardIcon(getattr(QStyle, n))
            bar.addAction(QAction(ico, n, self))

if __name__ == "__main__":
    app = QApplication(sys.argv)
    win = MainWindow()
    win.show()
    sys.exit(app.exec())